package single;


import java.util.ArrayList;
import java.util.List;

public class Singleton {
    public static void main(String[] args) {
        Person person1 = Person.getPerson();
        Person person2 = Person.getPerson();
        System.out.println(person1 == person2);

        Zoo z1 = Zoo.getInitZoo();
        Zoo z2 = Zoo.getInitZoo();
        System.out.println(z2 == z1);
        List<Zoo> list = Zoo.getList();
        list.forEach(System.out::print);


    }
}

class Person{
    private static final Person PERSON = new Person();
    private Person() {
    }

    public static Person getPerson() {
        return PERSON;
    }
}
class Zoo{
    private String name;
    private String sex;
    private String age;
    static List<Zoo> list = new ArrayList<>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public Zoo(String name, String sex, String age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    private static Zoo ZOO = null;

    public Zoo() {
    }

    public static List<Zoo> getList() {
        return list;
    }

    public static Zoo getInitZoo() {
        if (ZOO == null) {
            ZOO = new Zoo();
            return ZOO;
        }
        return ZOO;
    }
    {

    }
    static{
        Zoo zoo1 = new Zoo("小黄","男","2");
        Zoo zoo2 = new Zoo("小绿","女","3");
        Zoo zoo3 = new Zoo("小黑","男","1");
        list.add(zoo1);
        list.add(zoo2);
        list.add(zoo3);
    }
}